package com.muki.succ.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.muki.succ.web.service.ThemeService;

@Controller
public class ThemeController {
	
	@Autowired private ThemeService themeService;
	
	class Theme {
		
		//主题名
		private String topic;
		
		//起始urk
		private List<String> start_Url;
		
		//爬虫数量
		private int SpiderNum;
		
		//存储路径
		private String save_path;

		public String getTopic() {
			return topic;
		}

		public void setTopic(String topic) {
			this.topic = topic;
		}

		public List<String> getStart_Url() {
			return start_Url;
		}

		public void setStart_Url(List<String> start_Url) {
			this.start_Url = start_Url;
		}

		public int getSpiderNum() {
			return SpiderNum;
		}

		public void setSpiderNum(int spiderNum) {
			SpiderNum = spiderNum;
		}

		public String getSave_path() {
			return save_path;
		}

		public void setSave_path(String save_path) {
			this.save_path = save_path;
		}
		
		
	}
	
	@RequestMapping(value="pubview")
	public String pubView() {
		return "pub";
	}
	
	@RequestMapping(value="task") 
	public String task() {
		return "task";
	}
	
	@RequestMapping(value="pub",method=RequestMethod.POST)
	public ModelAndView pubTheme(@RequestParam("theme")String theme,@RequestParam("num")int num) {
		try {
			themeService.pub(theme, num);
			return new ModelAndView("task");
		} catch (Exception e) {
			e.printStackTrace();
			return new ModelAndView("redirect:pubview");
		}
	}
	
	@RequestMapping(value="pubtask",method=RequestMethod.POST)
	@ResponseBody
	public boolean pubTask(@RequestParam("theme")String theme,@RequestParam("url")String url) {
		themeService.pubTask(theme, url);
		return true;
	}
	
}
